<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增药品')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-menu-add">
		<div class="col-md-6">
			<div class="form-group">
				<label class="col-sm-3 control-label">药品名称：</label>
				<div class="col-sm-9">
					<input id ="name" type="text" name="name" class="form-control" placeholder="请输入药品名称">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">制药单位：</label>
				<div class="col-sm-9">
					<input id="dept" type="text" name="dept" class="form-control" placeholder="请输入制药单位">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">有效期：</label>
				<div class="col-sm-9">
					<input id="validity" type="text" name="validity" class="form-control" placeholder="请输入有效期">
				</div>
			</div>
		</div>
		<div class="col-md-6">
			<div class="form-group">
				<label class="col-sm-3 control-label">药品类型：</label>
				<div class="col-xs-4">
					<select id="typeId" class="form-control">
						<option th:each="type:${types}" th:value="${type.id}" th:text="${type.typename}" th:disabled="${type.del_flag == '1'}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">价格：</label>
				<div class="col-sm-9">
					<input id="price" type="number" name="price" class="form-control" placeholder="请输入价格">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">疗效：</label>
				<div class="col-sm-9">
					<textarea id="effect" type="text" name="effect" class="form-control" placeholder="请输入疗效"></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">药盒照片：</label>
				<input id="filePath" name="filePath" class="form-control" type="file" style="padding: 3px 6px;
                padding-left: 10px;
                border: 1px solid #E7EAEC;
                width: 230px;
                height: 25px;
                line-height: 25px;
                border-left: 3px solid #3FB7EB;
                background: #FAFAFB;
                border-radius: 2px;
                 border: 0px;" >
			</div>
		</div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script>
	function submitHandler() {
		add();
	}
	function add() {
		var name = $("input[name='name']").val();
		var dept = $("input[name='dept']").val();
		var typeId = $('#typeId option:selected').val();
		var validity = $('#validity').val();
		var price = $('#price').val();
		var effect = $('#effect').val();


		if ($('#filePath')[0].files[0] == null) {
			$.modal.alertWarning("请先选择文件路径");
			return false;
		}
		var formData = new FormData();
		formData.append('name', name);
		formData.append('dept', dept);
		formData.append('typeId', typeId);
		formData.append('validity', validity);
		formData.append('price', price);
		formData.append('effect', effect);
		formData.append('fileName', $("#fileName").val());
		formData.append('file', $('#filePath')[0].files[0]);
		$.ajax({
			processData: false,
			contentType: false,
			cache: false,
			type: "POST",
			url: ctx + "system/drug/add",
			data: formData,
			async: false,
			error: function (request) {
				$.modal.alertError("系统错误");
			},
			success: function (data) {
				$.operate.successCallback(data);
			}
		});
	}
</script>
</body>
</html>
